<<if ($defaulttext != "")>>
<div class="defaulttext">
<<$defaulttext>>
</div>
<</if>>
<table class="searchtable" width="100%">
<tr class="input">
<td colspan=2>
<<hsinput value="<<$searchvalue>>" class="first" id="export_product_freetext" name="product_export">>
</td>
<td>
<img id="export_products_down" src="site/resources/img/icons/down.png" height=27 style="position:relative;top:2px;left:-20px;">
</td>
<td class="text">
<div style="position:relative;left:-8px;">or</div>
</td>
<td>
<nobr>
<input class="companysearch" name="companysearch" type="text">
</td>
<td>
<button onclick="searchClicked(false)">search</button>
</td>
<td width="50%" style="text-align:right;">
<<if ($user.company_profile_id > 0 && $user.registertype == "1")>>
<a href="index.php?choice=profile">Update your company profile</a>
<<elseif (!$loggedin)>>
<a href="index.php?choice=login">List your company</a>
<</if>>
</td>
</tr>
</table>

<script>
var activeSearchComponent = "";

jQuery(".hsinput").hsInput({
    page : "companyprofile",
    hs2service : "geths2",
    hs4service : "geths4fromhs2",
    freetextservice : "gethsdata",
    emptyOnFocus : true,
    defaulttext : "by product name / HS code",
    change : function() {
        activeSearchComponent = "hs";
        jQuery(".companysearch").freetextsearch("closelist");
    }
//    enterHandler : handleEnterKey
});

jQuery(".companysearch").freetextsearch({
    sourcepage : "exportproducts",
    resultpage : "list_exportproducts",
    resultsubpage : "viewlist",
    filterservice : "getcompanieslike",
    defaulttext : "by company name",
    change : function() {
        activeSearchComponent = "company";
        jQuery("input#export_product_freetext").hsInput("closelist");
    }
});

function dropdownopen() {
    jQuery(".companysearch").freetextsearch("closelist");
}


jQuery("input#export_product_freetext").dblclick(function() {
    searchClicked(false);
});
jQuery("input[name='companysearch']").dblclick(function() {
    searchClicked(false);
});

jQuery("input#export_product_freetext").keyup(function(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    if (code == 13) {
        searchClicked(false);
    }
});

function searchClicked(newWindow) {
    if (activeSearchComponent == "hs") {
        var input = jQuery("input#export_product_freetext").val();
        if (isNaN(parseInt(input.split(" ")[0], 10))) {
            startSearch({
                freetext : encodeURIComponent(input),
                enteredText : encodeURIComponent(input)
            }, false);
        } else {
            startSearch({
                hs4 : input.split(" ")[0],
                hs2 : getHS2FromHS4(input.split(" ")[0]),
                enteredText : encodeURIComponent(input)
            }, false);
        }
    } else if (activeSearchComponent == "company") {
        var selectedValue = jQuery("select#companysearch_list").find("option:selected").val();
        if (selectedValue) {
            redirect("list_exportproducts", "viewlist", {
                selectedItem : selectedValue
            }, false);
        }
    }
}

</script>
